{extend name="layout/default" /}
{block name="head"}
<title>switch demo</title>
{/block}
{block name="content"}

<div class="ok-body">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>Layui switch演示</legend>
    </fieldset>

    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="checkbox" name="status" value="1" lay-skin="switch" lay-filter="switchTest"
                    checked="checked" lay-text="正常|关闭">
            </div>
        </div>
    </form>
</div>
{/block}
{block name="scripts"}

<script>
    // 状态监听开关
    layui.use(['form'], function () {
        var form = layui.form
            , layer = layui.layer;
        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            if (this.checked) {
                layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                    offset: '6px'
                });
                //layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅 仅是ON|OFF', data.othis)
            } else {
                layer.msg('开关： 关掉了', {
                    offset: '6px'
                });
            }
            //do some ajax opeartiopns;
        });
    });
</script>

{/block}